import { h0 } from '../common/fp';
//出发日期
export const ACTION_SET_DEPARTDATE = 'ACTION_SET_DEPARTDATE';
//到达日期
export const ACTION_SET_ARRIVEDATE = 'ACTION_SET_ARRIVEDATE';
//出发时间
export const ACTION_SET_DEPARTTIMESTR = 'ACTION_SET_DEPARTTIMESTR';
//到达时间
export const ACTION_SET_ARRIVETIMESTR = 'ACTION_SET_ARRIVETIMESTR';
//出发车站
export const ACTION_SET_DEPARTSTATION = 'ACTION_SET_DEPARTSTATION';
//到达车站
export const ACTION_SET_ARRIVESTATION = 'ACTION_SET_ARRIVESTATION';
//车次
export const ACTION_SET_TRAINNUMBER = 'ACTION_SET_TRAINNUMBER';
//运行时间
export const ACTION_SET_DURATIONSTR = 'ACTION_SET_DURATIONSTR';
//座次和售票渠道
export const ACTION_SET_TICKETS = 'ACTION_SET_TICKETS';
//小浮层弹出
export const ACTION_SET_ISSCHEDUALVISIBLE = 'ACTION_SET_ISSCHEDUALVISIBLE';
//解析location的url参数
export const ACTION_SET_SEARCHPARSED = 'ACTION_SET_SEARCHPARSED';

//出发日期
export function setDepartDate(departDate) {
    return {
        type: ACTION_SET_DEPARTDATE,
        payload: departDate,
    };
}
//到达日期
export function setArriveDate(arriveDate) {
    return {
        type: ACTION_SET_ARRIVEDATE,
        payload: arriveDate,
    };
}
//出发时间  从服务端获取数据
export function setDepartTimeStr(departTimeStr) {
    return {
        type: ACTION_SET_DEPARTTIMESTR,
        payload: departTimeStr,
    };
}
//到达时间
export function setArriveTimeStr(arriveTimeStr) {
    return {
        type: ACTION_SET_ARRIVETIMESTR,
        payload: arriveTimeStr,
    };
}
//出发车站
export function setDepartStation(departStation) {
    return {
        type: ACTION_SET_DEPARTSTATION,
        payload: departStation,
    };
}
//到达车站
export function setArriveStation(arriveStation) {
    return {
        type: ACTION_SET_ARRIVESTATION,
        payload: arriveStation,
    };
}
//车次
export function setTrainNumber(trainNumber) {
    return {
        type: ACTION_SET_TRAINNUMBER,
        payload: trainNumber,
    };
}
//运行时间
export function setDurationStr(durationStr) {
    return {
        type: ACTION_SET_DURATIONSTR,
        payload: durationStr,
    };
}
//座次和售票渠道
export function setTickets(tickets) {
    return {
        type: ACTION_SET_TICKETS,
        payload: tickets,
    };
}
//小浮层弹出
export function setIsSchedualVisible(isSchedualVisible) {
    return {
        type: ACTION_SET_ISSCHEDUALVISIBLE,
        payload: isSchedualVisible,
    };
}
export function toggleIsSchedualVisible() {
    return (dispatch, getState) => {
        const { isSchedualVisible } = getState();
        dispatch(setIsSchedualVisible(!isSchedualVisible));
    };
}
//解析location的url参数
export function setSearchParsed(searchParsed) {
    return {
        type: ACTION_SET_SEARCHPARSED,
        payload: searchParsed,
    };
}
//设置后一天
export const nextDay = () => {
    return (dispatch, getState) => {
        const { departDate } = getState();
        //往后一天
        dispatch(setDepartDate(h0(departDate) + 24 * 60 * 60 * 1000));
    };
};

// 设置前一天
export const prevDay = () => {
    return (dispatch, getState) => {
        const { departDate } = getState();
        //往后一天
        dispatch(setDepartDate(h0(departDate) - 24 * 60 * 60 * 1000));
    };
};
